<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">

        <form class="layui-form layui-form-pane" lay-filter="passwordInfo">

            <!--密码-->
            <div class="layui-form-item">
                <label class="layui-form-label">输入密码</label>
                <div class="layui-input-block">
                    <input type="password" name="password" lay-verify="required"
                           placeholder="请输入密码" autocomplete="off" class="layui-input" id="password">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">确认密码</label>
                <div class="layui-input-block">
                    <input type="password" name="repassword" lay-verify="required"
                           placeholder="请输入密码" autocomplete="off" class="layui-input" id="repassword">
                </div>
            </div>

            <div class="layui-form-item">
                <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="passwordInfo">提交</button>
            </div>
        </form>
    </div>
</div>
<script>
    layui.use(['jquery', 'form', 'layer'], function () {
        var $ = layui.jquery
            ,form = layui.form;

        form.render();


        var eduTeacher = JSON.parse(sessionStorage.getItem("eduTeacher"));

        //表单提交
        form.on('submit(passwordInfo)',function (data) {
            //判断两次输入密码是否一致
            var password = $("#password").val();
            var repassword = $("#repassword").val();

            //判断密码是否相等
            if(password != repassword){
                layer.msg("两次输入密码不一致");
                $("#password").val("");
                $("#repassword").val("");
                return false;
            }
            $.post({
                url: "http://localhost/api/teacher/password",
                headers: {"token": eduTeacher.token},
                data: {
                    "id": eduTeacher.id,
                    "name": eduTeacher.name,
                    "salt": eduTeacher.salt,
                    "password": password
                },
                success: function (){
                    layer.msg("修改密码成功", function () {
                        sessionStorage.removeItem("eduTeacher");
                        window.location.reload();
                    })
                },error(){
                    layer.msg("修改密码失败")
                }
            });

            return false;
        })
    })
</script>